<?php

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class Tickets extends Model
{
    use SoftDelete;
    // Define the table name
    protected $name = 'tickets';
    public $timestamps = false;
    protected $deleteTime = 'deleted_at';

    public function scenicSpot()
    {
        return $this->hasOne(ScenicSpots::class, 'id', 'scenic_id');
    }


    public function batchTicketInfo($ticketIds)
    {
        $ticketInfo = $this->alias('t')
            ->leftJoin('scenic_spots s', 't.scenic_id = s.id')
            ->where('id', 'in', $ticketIds)
            ->field('t.*,s.name as spots_name,s.cover_image')
            ->select()
            ->toArray();
        foreach($ticketInfo as $key => $item){
            $ticketInfo[$key]['cover_image'] = env('IMAGE_URL').$item['cover_image'];
        }
        return $ticketInfo;
    }
}
